
/****** Object:  Stored Procedure [dbo].UsersDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spUsersDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spUsersDelete]
GO

/****** Object:  Stored Procedure [dbo].UsersGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spUsersGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spUsersGet]
GO

/****** Object:  Stored Procedure [dbo].UsersGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spUsersGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spUsersGetList]
GO

	
/****** Object:  Stored Procedure [dbo].UsersInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spUsersInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spUsersInsert]
GO

/****** Object:  Stored Procedure [dbo].UsersUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spUsersUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spUsersUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [dbo].spUsersDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:04:56 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [dbo].spUsersDelete
	@Mobile nvarchar(20)
AS

DELETE FROM [dbo].[Users]
WHERE
	[Mobile] = @Mobile
GO
	
/******************************************************************************
**		File: 
**		Name: [dbo].spUsersGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:04:56 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [dbo].spUsersGet
	@Mobile nvarchar(20)
AS

SELECT
	[Mobile],
	[Password],
	[Email],
	[Ten],
	[Ho],
	[NgSinh],
	[Phai],
	[DChi],
	[NhanMail],
	[NhanSMS],
	[ThanhPho],
	[Quan],
	[NgonNgu],
	[NguoiGioiThieu],
	[MaSoCaNhan]
FROM
	[dbo].[Users]
WHERE
	[Mobile] = @Mobile

GO
	
/******************************************************************************
**		File: 
**		Name: [dbo].spUsersGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:04:56 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [dbo].spUsersGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempUsers (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	Mobile nvarchar(20)	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempUsers ([Mobile]) SELECT '
SET @sql = @sql + ' [Mobile] FROM [dbo].[Users]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [Users]

SELECT
	[dbo].[Users].[Mobile],
	[Password],
	[Email],
	[Ten],
	[Ho],
	[NgSinh],
	[Phai],
	[DChi],
	[NhanMail],
	[NhanSMS],
	[ThanhPho],
	[Quan],
	[NgonNgu],
	[NguoiGioiThieu],
	[MaSoCaNhan]
FROM
	#TempUsers AS tblTemp JOIN [dbo].[Users] ON
	tblTemp.Mobile = [dbo].[Users].Mobile 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempUsers

GO

/******************************************************************************
**		File: 
**		Name: [dbo].spUsersInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:04:56 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [dbo].spUsersInsert
	@Mobile nvarchar(20),
	@Password nvarchar(50),
	@Email nchar(120),
	@Ten nvarchar(25),
	@Ho nvarchar(50),
	@NgSinh smalldatetime,
	@Phai nvarchar(20),
	@DChi nvarchar(250),
	@NhanMail bit,
	@NhanSMS bit,
	@ThanhPho int,
	@Quan int,
	@NgonNgu int,
	@NguoiGioiThieu nvarchar(20),
	@MaSoCaNhan nvarchar(20)
AS

INSERT INTO [dbo].[Users] 
(
	[Mobile],
	[Password],
	[Email],
	[Ten],
	[Ho],
	[NgSinh],
	[Phai],
	[DChi],
	[NhanMail],
	[NhanSMS],
	[ThanhPho],
	[Quan],
	[NgonNgu],
	[NguoiGioiThieu],
	[MaSoCaNhan]
) 
VALUES 
(
	@Mobile,
	@Password,
	@Email,
	@Ten,
	@Ho,
	@NgSinh,
	@Phai,
	@DChi,
	@NhanMail,
	@NhanSMS,
	@ThanhPho,
	@Quan,
	@NgonNgu,
	@NguoiGioiThieu,
	@MaSoCaNhan
)


GO
	
/******************************************************************************
**		File: 
**		Name: [dbo].spUsersUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:04:56 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [dbo].spUsersUpdate
	@Mobile nvarchar(20), 
	@Password nvarchar(50), 
	@Email nchar(120), 
	@Ten nvarchar(25), 
	@Ho nvarchar(50), 
	@NgSinh smalldatetime, 
	@Phai nvarchar(20), 
	@DChi nvarchar(250), 
	@NhanMail bit, 
	@NhanSMS bit, 
	@ThanhPho int, 
	@Quan int, 
	@NgonNgu int, 
	@NguoiGioiThieu nvarchar(20), 
	@MaSoCaNhan nvarchar(20) 
AS

UPDATE [dbo].[Users] SET
	[Password] = @Password,
	[Email] = @Email,
	[Ten] = @Ten,
	[Ho] = @Ho,
	[NgSinh] = @NgSinh,
	[Phai] = @Phai,
	[DChi] = @DChi,
	[NhanMail] = @NhanMail,
	[NhanSMS] = @NhanSMS,
	[ThanhPho] = @ThanhPho,
	[Quan] = @Quan,
	[NgonNgu] = @NgonNgu,
	[NguoiGioiThieu] = @NguoiGioiThieu,
	[MaSoCaNhan] = @MaSoCaNhan
WHERE
	[Mobile] = @Mobile

GO


/****** Object:  Stored Procedure [sapro].DanhMucDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDanhMucDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDanhMucDelete]
GO

/****** Object:  Stored Procedure [sapro].DanhMucGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDanhMucGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDanhMucGet]
GO

/****** Object:  Stored Procedure [sapro].DanhMucGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDanhMucGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDanhMucGetList]
GO

	
/****** Object:  Stored Procedure [sapro].DanhMucInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDanhMucInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDanhMucInsert]
GO

/****** Object:  Stored Procedure [sapro].DanhMucUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDanhMucUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDanhMucUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spDanhMucDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:08 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDanhMucDelete
	@MaDanhMuc int
AS

DELETE FROM [sapro].[DanhMuc]
WHERE
	[MaDanhMuc] = @MaDanhMuc
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spDanhMucGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:08 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDanhMucGet
	@MaDanhMuc int
AS

SELECT
	[MaDanhMuc],
	[TenDanhMuc],
	[ThuocDanhMuc],
	[LoaiDanhMuc]
FROM
	[sapro].[DanhMuc]
WHERE
	[MaDanhMuc] = @MaDanhMuc

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spDanhMucGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:08 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDanhMucGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempDanhMuc (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaDanhMuc int	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempDanhMuc ([MaDanhMuc]) SELECT '
SET @sql = @sql + ' [MaDanhMuc] FROM [sapro].[DanhMuc]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [DanhMuc]

SELECT
	[sapro].[DanhMuc].[MaDanhMuc],
	[TenDanhMuc],
	[ThuocDanhMuc],
	[LoaiDanhMuc]
FROM
	#TempDanhMuc AS tblTemp JOIN [sapro].[DanhMuc] ON
	tblTemp.MaDanhMuc = [sapro].[DanhMuc].MaDanhMuc 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempDanhMuc

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spDanhMucInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:08 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDanhMucInsert
	@MaDanhMuc int,
	@TenDanhMuc nvarchar(150),
	@ThuocDanhMuc int,
	@LoaiDanhMuc int
AS

INSERT INTO [sapro].[DanhMuc] 
(
	[MaDanhMuc],
	[TenDanhMuc],
	[ThuocDanhMuc],
	[LoaiDanhMuc]
) 
VALUES 
(
	@MaDanhMuc,
	@TenDanhMuc,
	@ThuocDanhMuc,
	@LoaiDanhMuc
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spDanhMucUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:08 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDanhMucUpdate
	@MaDanhMuc int, 
	@TenDanhMuc nvarchar(150), 
	@ThuocDanhMuc int, 
	@LoaiDanhMuc int 
AS

UPDATE [sapro].[DanhMuc] SET
	[TenDanhMuc] = @TenDanhMuc,
	[ThuocDanhMuc] = @ThuocDanhMuc,
	[LoaiDanhMuc] = @LoaiDanhMuc
WHERE
	[MaDanhMuc] = @MaDanhMuc

GO


/****** Object:  Stored Procedure [sapro].DoiTacDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDoiTacDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDoiTacDelete]
GO

/****** Object:  Stored Procedure [sapro].DoiTacGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDoiTacGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDoiTacGet]
GO

/****** Object:  Stored Procedure [sapro].DoiTacGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDoiTacGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDoiTacGetList]
GO

	
/****** Object:  Stored Procedure [sapro].DoiTacInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDoiTacInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDoiTacInsert]
GO

/****** Object:  Stored Procedure [sapro].DoiTacUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spDoiTacUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spDoiTacUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spDoiTacDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:11 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDoiTacDelete
	@MaDoiTac int
AS

DELETE FROM [sapro].[DoiTac]
WHERE
	[MaDoiTac] = @MaDoiTac
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spDoiTacGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:11 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDoiTacGet
	@MaDoiTac int
AS

SELECT
	[MaDoiTac],
	[TenDoiTac],
	[NoiDung],
	[ChiTiet],
	[DanhMucDoiTac]
FROM
	[sapro].[DoiTac]
WHERE
	[MaDoiTac] = @MaDoiTac

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spDoiTacGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:11 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDoiTacGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempDoiTac (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaDoiTac int	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempDoiTac ([MaDoiTac]) SELECT '
SET @sql = @sql + ' [MaDoiTac] FROM [sapro].[DoiTac]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [DoiTac]

SELECT
	[sapro].[DoiTac].[MaDoiTac],
	[TenDoiTac],
	[NoiDung],
	[ChiTiet],
	[DanhMucDoiTac]
FROM
	#TempDoiTac AS tblTemp JOIN [sapro].[DoiTac] ON
	tblTemp.MaDoiTac = [sapro].[DoiTac].MaDoiTac 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempDoiTac

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spDoiTacInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:11 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDoiTacInsert
	@MaDoiTac int,
	@TenDoiTac nvarchar(150),
	@NoiDung nvarchar(255),
	@ChiTiet nvarchar,
	@DanhMucDoiTac int
AS

INSERT INTO [sapro].[DoiTac] 
(
	[MaDoiTac],
	[TenDoiTac],
	[NoiDung],
	[ChiTiet],
	[DanhMucDoiTac]
) 
VALUES 
(
	@MaDoiTac,
	@TenDoiTac,
	@NoiDung,
	@ChiTiet,
	@DanhMucDoiTac
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spDoiTacUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:11 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spDoiTacUpdate
	@MaDoiTac int, 
	@TenDoiTac nvarchar(150), 
	@NoiDung nvarchar(255), 
	@ChiTiet nvarchar, 
	@DanhMucDoiTac int 
AS

UPDATE [sapro].[DoiTac] SET
	[TenDoiTac] = @TenDoiTac,
	[NoiDung] = @NoiDung,
	[ChiTiet] = @ChiTiet,
	[DanhMucDoiTac] = @DanhMucDoiTac
WHERE
	[MaDoiTac] = @MaDoiTac

GO


/****** Object:  Stored Procedure [sapro].GiaoDichDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spGiaoDichDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spGiaoDichDelete]
GO

/****** Object:  Stored Procedure [sapro].GiaoDichGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spGiaoDichGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spGiaoDichGet]
GO

/****** Object:  Stored Procedure [sapro].GiaoDichGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spGiaoDichGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spGiaoDichGetList]
GO

	
/****** Object:  Stored Procedure [sapro].GiaoDichInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spGiaoDichInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spGiaoDichInsert]
GO

/****** Object:  Stored Procedure [sapro].GiaoDichUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spGiaoDichUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spGiaoDichUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spGiaoDichDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:15 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spGiaoDichDelete
	@Mobile nvarchar(20),
	@NgayGD datetime,
	@GioGD datetime
AS

DELETE FROM [sapro].[GiaoDich]
WHERE
	[Mobile] = @Mobile
	AND [NgayGD] = @NgayGD
	AND [GioGD] = @GioGD
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spGiaoDichGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:15 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spGiaoDichGet
	@Mobile nvarchar(20),
	@NgayGD datetime,
	@GioGD datetime
AS

SELECT
	[Mobile],
	[NgayGD],
	[GioGD],
	[SoDiemTruoc],
	[SoDiemGD],
	[SoDiemSau],
	[NoiDung]
FROM
	[sapro].[GiaoDich]
WHERE
	[Mobile] = @Mobile
	AND [NgayGD] = @NgayGD
	AND [GioGD] = @GioGD

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spGiaoDichGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:15 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spGiaoDichGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempGiaoDich (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	Mobile nvarchar(20),	
	NgayGD datetime,	
	GioGD datetime	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempGiaoDich ([Mobile],[NgayGD],[GioGD]) SELECT '
SET @sql = @sql + ' [Mobile],[NgayGD],[GioGD] FROM [sapro].[GiaoDich]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [GiaoDich]

SELECT
	[sapro].[GiaoDich].[Mobile],
	[sapro].[GiaoDich].[NgayGD],
	[sapro].[GiaoDich].[GioGD],
	[SoDiemTruoc],
	[SoDiemGD],
	[SoDiemSau],
	[NoiDung]
FROM
	#TempGiaoDich AS tblTemp JOIN [sapro].[GiaoDich] ON
	tblTemp.Mobile = [sapro].[GiaoDich].Mobile  AND 	
	tblTemp.NgayGD = [sapro].[GiaoDich].NgayGD  AND 	
	tblTemp.GioGD = [sapro].[GiaoDich].GioGD 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempGiaoDich

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spGiaoDichInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:15 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spGiaoDichInsert
	@Mobile nvarchar(20),
	@NgayGD datetime,
	@GioGD datetime,
	@SoDiemTruoc int,
	@SoDiemGD int,
	@SoDiemSau int,
	@NoiDung nvarchar(255)
AS

INSERT INTO [sapro].[GiaoDich] 
(
	[Mobile],
	[NgayGD],
	[GioGD],
	[SoDiemTruoc],
	[SoDiemGD],
	[SoDiemSau],
	[NoiDung]
) 
VALUES 
(
	@Mobile,
	@NgayGD,
	@GioGD,
	@SoDiemTruoc,
	@SoDiemGD,
	@SoDiemSau,
	@NoiDung
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spGiaoDichUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:15 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spGiaoDichUpdate
	@Mobile nvarchar(20), 
	@NgayGD datetime, 
	@GioGD datetime, 
	@SoDiemTruoc int, 
	@SoDiemGD int, 
	@SoDiemSau int, 
	@NoiDung nvarchar(255) 
AS

UPDATE [sapro].[GiaoDich] SET
	[SoDiemTruoc] = @SoDiemTruoc,
	[SoDiemGD] = @SoDiemGD,
	[SoDiemSau] = @SoDiemSau,
	[NoiDung] = @NoiDung
WHERE
	[Mobile] = @Mobile
	AND [NgayGD] = @NgayGD
	AND [GioGD] = @GioGD

GO


/****** Object:  Stored Procedure [sapro].HoTroTrucTuyenDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spHoTroTrucTuyenDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spHoTroTrucTuyenDelete]
GO

/****** Object:  Stored Procedure [sapro].HoTroTrucTuyenGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spHoTroTrucTuyenGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spHoTroTrucTuyenGet]
GO

/****** Object:  Stored Procedure [sapro].HoTroTrucTuyenGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spHoTroTrucTuyenGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spHoTroTrucTuyenGetList]
GO

	
/****** Object:  Stored Procedure [sapro].HoTroTrucTuyenInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spHoTroTrucTuyenInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spHoTroTrucTuyenInsert]
GO

/****** Object:  Stored Procedure [sapro].HoTroTrucTuyenUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spHoTroTrucTuyenUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spHoTroTrucTuyenUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spHoTroTrucTuyenDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:26 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spHoTroTrucTuyenDelete
	@MaNguoiHoTro int
AS

DELETE FROM [sapro].[HoTroTrucTuyen]
WHERE
	[MaNguoiHoTro] = @MaNguoiHoTro
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spHoTroTrucTuyenGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:26 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spHoTroTrucTuyenGet
	@MaNguoiHoTro int
AS

SELECT
	[MaNguoiHoTro],
	[TenNguoiHoTro],
	[YahooAccount],
	[GmailAccount],
	[HotmailAccount],
	[SkyAccount]
FROM
	[sapro].[HoTroTrucTuyen]
WHERE
	[MaNguoiHoTro] = @MaNguoiHoTro

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spHoTroTrucTuyenGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:26 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spHoTroTrucTuyenGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempHoTroTrucTuyen (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaNguoiHoTro int	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempHoTroTrucTuyen ([MaNguoiHoTro]) SELECT '
SET @sql = @sql + ' [MaNguoiHoTro] FROM [sapro].[HoTroTrucTuyen]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [HoTroTrucTuyen]

SELECT
	[sapro].[HoTroTrucTuyen].[MaNguoiHoTro],
	[TenNguoiHoTro],
	[YahooAccount],
	[GmailAccount],
	[HotmailAccount],
	[SkyAccount]
FROM
	#TempHoTroTrucTuyen AS tblTemp JOIN [sapro].[HoTroTrucTuyen] ON
	tblTemp.MaNguoiHoTro = [sapro].[HoTroTrucTuyen].MaNguoiHoTro 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempHoTroTrucTuyen

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spHoTroTrucTuyenInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:26 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spHoTroTrucTuyenInsert
	@MaNguoiHoTro int,
	@TenNguoiHoTro nvarchar(50),
	@YahooAccount nvarchar(50),
	@GmailAccount nvarchar(50),
	@HotmailAccount nvarchar(50),
	@SkyAccount nvarchar(50)
AS

INSERT INTO [sapro].[HoTroTrucTuyen] 
(
	[MaNguoiHoTro],
	[TenNguoiHoTro],
	[YahooAccount],
	[GmailAccount],
	[HotmailAccount],
	[SkyAccount]
) 
VALUES 
(
	@MaNguoiHoTro,
	@TenNguoiHoTro,
	@YahooAccount,
	@GmailAccount,
	@HotmailAccount,
	@SkyAccount
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spHoTroTrucTuyenUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:26 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spHoTroTrucTuyenUpdate
	@MaNguoiHoTro int, 
	@TenNguoiHoTro nvarchar(50), 
	@YahooAccount nvarchar(50), 
	@GmailAccount nvarchar(50), 
	@HotmailAccount nvarchar(50), 
	@SkyAccount nvarchar(50) 
AS

UPDATE [sapro].[HoTroTrucTuyen] SET
	[TenNguoiHoTro] = @TenNguoiHoTro,
	[YahooAccount] = @YahooAccount,
	[GmailAccount] = @GmailAccount,
	[HotmailAccount] = @HotmailAccount,
	[SkyAccount] = @SkyAccount
WHERE
	[MaNguoiHoTro] = @MaNguoiHoTro

GO


/****** Object:  Stored Procedure [sapro].LienHeDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLienHeDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLienHeDelete]
GO

/****** Object:  Stored Procedure [sapro].LienHeGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLienHeGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLienHeGet]
GO

/****** Object:  Stored Procedure [sapro].LienHeGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLienHeGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLienHeGetList]
GO

	
/****** Object:  Stored Procedure [sapro].LienHeInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLienHeInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLienHeInsert]
GO

/****** Object:  Stored Procedure [sapro].LienHeUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLienHeUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLienHeUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spLienHeDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:30 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLienHeDelete
	@Email nchar(10)
AS

DELETE FROM [sapro].[LienHe]
WHERE
	[Email] = @Email
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spLienHeGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:30 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLienHeGet
	@Email nchar(10)
AS

SELECT
	[HoTen],
	[Email],
	[TieuDe],
	[NoiDung]
FROM
	[sapro].[LienHe]
WHERE
	[Email] = @Email

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spLienHeGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:30 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLienHeGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempLienHe (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	Email nchar(10)	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempLienHe ([Email]) SELECT '
SET @sql = @sql + ' [Email] FROM [sapro].[LienHe]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [LienHe]

SELECT
	[HoTen],
	[sapro].[LienHe].[Email],
	[TieuDe],
	[NoiDung]
FROM
	#TempLienHe AS tblTemp JOIN [sapro].[LienHe] ON
	tblTemp.Email = [sapro].[LienHe].Email 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempLienHe

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spLienHeInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:30 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLienHeInsert
	@HoTen nchar(10),
	@Email nchar(10),
	@TieuDe nchar(10),
	@NoiDung nchar(10)
AS

INSERT INTO [sapro].[LienHe] 
(
	[HoTen],
	[Email],
	[TieuDe],
	[NoiDung]
) 
VALUES 
(
	@HoTen,
	@Email,
	@TieuDe,
	@NoiDung
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spLienHeUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:30 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLienHeUpdate
	@HoTen nchar(10), 
	@Email nchar(10), 
	@TieuDe nchar(10), 
	@NoiDung nchar(10) 
AS

UPDATE [sapro].[LienHe] SET
	[HoTen] = @HoTen,
	[TieuDe] = @TieuDe,
	[NoiDung] = @NoiDung
WHERE
	[Email] = @Email

GO


/****** Object:  Stored Procedure [sapro].LoaiDanhMucDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLoaiDanhMucDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLoaiDanhMucDelete]
GO

/****** Object:  Stored Procedure [sapro].LoaiDanhMucGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLoaiDanhMucGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLoaiDanhMucGet]
GO

/****** Object:  Stored Procedure [sapro].LoaiDanhMucGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLoaiDanhMucGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLoaiDanhMucGetList]
GO

	
/****** Object:  Stored Procedure [sapro].LoaiDanhMucInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLoaiDanhMucInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLoaiDanhMucInsert]
GO

/****** Object:  Stored Procedure [sapro].LoaiDanhMucUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spLoaiDanhMucUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spLoaiDanhMucUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spLoaiDanhMucDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:32 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLoaiDanhMucDelete
	@MaLoaiDanhMuc int
AS

DELETE FROM [sapro].[LoaiDanhMuc]
WHERE
	[MaLoaiDanhMuc] = @MaLoaiDanhMuc
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spLoaiDanhMucGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:32 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLoaiDanhMucGet
	@MaLoaiDanhMuc int
AS

SELECT
	[MaLoaiDanhMuc],
	[TenLoaiDanhMuc]
FROM
	[sapro].[LoaiDanhMuc]
WHERE
	[MaLoaiDanhMuc] = @MaLoaiDanhMuc

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spLoaiDanhMucGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:32 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLoaiDanhMucGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempLoaiDanhMuc (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaLoaiDanhMuc int	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempLoaiDanhMuc ([MaLoaiDanhMuc]) SELECT '
SET @sql = @sql + ' [MaLoaiDanhMuc] FROM [sapro].[LoaiDanhMuc]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [LoaiDanhMuc]

SELECT
	[sapro].[LoaiDanhMuc].[MaLoaiDanhMuc],
	[TenLoaiDanhMuc]
FROM
	#TempLoaiDanhMuc AS tblTemp JOIN [sapro].[LoaiDanhMuc] ON
	tblTemp.MaLoaiDanhMuc = [sapro].[LoaiDanhMuc].MaLoaiDanhMuc 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempLoaiDanhMuc

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spLoaiDanhMucInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:32 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLoaiDanhMucInsert
	@MaLoaiDanhMuc int,
	@TenLoaiDanhMuc nvarchar(150)
AS

INSERT INTO [sapro].[LoaiDanhMuc] 
(
	[MaLoaiDanhMuc],
	[TenLoaiDanhMuc]
) 
VALUES 
(
	@MaLoaiDanhMuc,
	@TenLoaiDanhMuc
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spLoaiDanhMucUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:32 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spLoaiDanhMucUpdate
	@MaLoaiDanhMuc int, 
	@TenLoaiDanhMuc nvarchar(150) 
AS

UPDATE [sapro].[LoaiDanhMuc] SET
	[TenLoaiDanhMuc] = @TenLoaiDanhMuc
WHERE
	[MaLoaiDanhMuc] = @MaLoaiDanhMuc

GO


/****** Object:  Stored Procedure [sapro].QuangCaoDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spQuangCaoDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spQuangCaoDelete]
GO

/****** Object:  Stored Procedure [sapro].QuangCaoGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spQuangCaoGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spQuangCaoGet]
GO

/****** Object:  Stored Procedure [sapro].QuangCaoGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spQuangCaoGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spQuangCaoGetList]
GO

	
/****** Object:  Stored Procedure [sapro].QuangCaoInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spQuangCaoInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spQuangCaoInsert]
GO

/****** Object:  Stored Procedure [sapro].QuangCaoUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spQuangCaoUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spQuangCaoUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spQuangCaoDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:34 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spQuangCaoDelete
	@MaQuangCao int
AS

DELETE FROM [sapro].[QuangCao]
WHERE
	[MaQuangCao] = @MaQuangCao
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spQuangCaoGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:34 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spQuangCaoGet
	@MaQuangCao int
AS

SELECT
	[MaQuangCao],
	[TenQuangCao],
	[NoiDung],
	[ChiTiet],
	[ThuocDanhMuc]
FROM
	[sapro].[QuangCao]
WHERE
	[MaQuangCao] = @MaQuangCao

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spQuangCaoGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:34 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spQuangCaoGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempQuangCao (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaQuangCao int	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempQuangCao ([MaQuangCao]) SELECT '
SET @sql = @sql + ' [MaQuangCao] FROM [sapro].[QuangCao]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [QuangCao]

SELECT
	[sapro].[QuangCao].[MaQuangCao],
	[TenQuangCao],
	[NoiDung],
	[ChiTiet],
	[ThuocDanhMuc]
FROM
	#TempQuangCao AS tblTemp JOIN [sapro].[QuangCao] ON
	tblTemp.MaQuangCao = [sapro].[QuangCao].MaQuangCao 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempQuangCao

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spQuangCaoInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:34 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spQuangCaoInsert
	@MaQuangCao int,
	@TenQuangCao nchar(10),
	@NoiDung nchar(10),
	@ChiTiet nchar(10),
	@ThuocDanhMuc int
AS

INSERT INTO [sapro].[QuangCao] 
(
	[MaQuangCao],
	[TenQuangCao],
	[NoiDung],
	[ChiTiet],
	[ThuocDanhMuc]
) 
VALUES 
(
	@MaQuangCao,
	@TenQuangCao,
	@NoiDung,
	@ChiTiet,
	@ThuocDanhMuc
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spQuangCaoUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:34 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spQuangCaoUpdate
	@MaQuangCao int, 
	@TenQuangCao nchar(10), 
	@NoiDung nchar(10), 
	@ChiTiet nchar(10), 
	@ThuocDanhMuc int 
AS

UPDATE [sapro].[QuangCao] SET
	[TenQuangCao] = @TenQuangCao,
	[NoiDung] = @NoiDung,
	[ChiTiet] = @ChiTiet,
	[ThuocDanhMuc] = @ThuocDanhMuc
WHERE
	[MaQuangCao] = @MaQuangCao

GO


/****** Object:  Stored Procedure [sapro].SanPhamDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spSanPhamDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spSanPhamDelete]
GO

/****** Object:  Stored Procedure [sapro].SanPhamGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spSanPhamGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spSanPhamGet]
GO

/****** Object:  Stored Procedure [sapro].SanPhamGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spSanPhamGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spSanPhamGetList]
GO

	
/****** Object:  Stored Procedure [sapro].SanPhamInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spSanPhamInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spSanPhamInsert]
GO

/****** Object:  Stored Procedure [sapro].SanPhamUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spSanPhamUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spSanPhamUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spSanPhamDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:37 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spSanPhamDelete
	@MaSanPham nvarchar(50)
AS

DELETE FROM [sapro].[SanPham]
WHERE
	[MaSanPham] = @MaSanPham
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spSanPhamGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:37 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spSanPhamGet
	@MaSanPham nvarchar(50)
AS

SELECT
	[MaSanPham],
	[TenSanPham],
	[SoDiem],
	[NoiDung],
	[ChiTiet],
	[DanhMuc],
	[AnhDaiDien],
	[AnhLon]
FROM
	[sapro].[SanPham]
WHERE
	[MaSanPham] = @MaSanPham

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spSanPhamGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:37 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spSanPhamGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempSanPham (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaSanPham nvarchar(50)	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempSanPham ([MaSanPham]) SELECT '
SET @sql = @sql + ' [MaSanPham] FROM [sapro].[SanPham]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [SanPham]

SELECT
	[sapro].[SanPham].[MaSanPham],
	[TenSanPham],
	[SoDiem],
	[NoiDung],
	[ChiTiet],
	[DanhMuc],
	[AnhDaiDien],
	[AnhLon]
FROM
	#TempSanPham AS tblTemp JOIN [sapro].[SanPham] ON
	tblTemp.MaSanPham = [sapro].[SanPham].MaSanPham 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempSanPham

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spSanPhamInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:37 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spSanPhamInsert
	@MaSanPham nvarchar(50),
	@TenSanPham nvarchar(150),
	@SoDiem int,
	@NoiDung nvarchar(255),
	@ChiTiet nvarchar,
	@DanhMuc int,
	@AnhDaiDien nvarchar(150),
	@AnhLon nvarchar(150)
AS

INSERT INTO [sapro].[SanPham] 
(
	[MaSanPham],
	[TenSanPham],
	[SoDiem],
	[NoiDung],
	[ChiTiet],
	[DanhMuc],
	[AnhDaiDien],
	[AnhLon]
) 
VALUES 
(
	@MaSanPham,
	@TenSanPham,
	@SoDiem,
	@NoiDung,
	@ChiTiet,
	@DanhMuc,
	@AnhDaiDien,
	@AnhLon
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spSanPhamUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:37 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spSanPhamUpdate
	@MaSanPham nvarchar(50), 
	@TenSanPham nvarchar(150), 
	@SoDiem int, 
	@NoiDung nvarchar(255), 
	@ChiTiet nvarchar, 
	@DanhMuc int, 
	@AnhDaiDien nvarchar(150), 
	@AnhLon nvarchar(150) 
AS

UPDATE [sapro].[SanPham] SET
	[TenSanPham] = @TenSanPham,
	[SoDiem] = @SoDiem,
	[NoiDung] = @NoiDung,
	[ChiTiet] = @ChiTiet,
	[DanhMuc] = @DanhMuc,
	[AnhDaiDien] = @AnhDaiDien,
	[AnhLon] = @AnhLon
WHERE
	[MaSanPham] = @MaSanPham

GO


/****** Object:  Stored Procedure [sapro].YeuCauDelete    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spYeuCauDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spYeuCauDelete]
GO

/****** Object:  Stored Procedure [sapro].YeuCauGet    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spYeuCauGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spYeuCauGet]
GO

/****** Object:  Stored Procedure [sapro].YeuCauGetList    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spYeuCauGetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spYeuCauGetList]
GO

	
/****** Object:  Stored Procedure [sapro].YeuCauInsert    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spYeuCauInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spYeuCauInsert]
GO

/****** Object:  Stored Procedure [sapro].YeuCauUpdate    Script Date: Thursday, March 18, 2010 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spYeuCauUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [sapro].[spYeuCauUpdate]
GO


/******************************************************************************
**		File: 
**		Name: [sapro].spYeuCauDelete
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:43 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spYeuCauDelete
	@MaYeuCau int
AS

DELETE FROM [sapro].[YeuCau]
WHERE
	[MaYeuCau] = @MaYeuCau
GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spYeuCauGet
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:43 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spYeuCauGet
	@MaYeuCau int
AS

SELECT
	[Mobile],
	[MaYeuCau],
	[NoiDungYeuCau]
FROM
	[sapro].[YeuCau]
WHERE
	[MaYeuCau] = @MaYeuCau

GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spYeuCauGetList
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:43 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spYeuCauGetList
	@OrderBy varchar(50),
	@OrderDirection varchar(5),
	@Page int,
	@PageSize int,
	@TotalRecords int output
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

CREATE TABLE #TempYeuCau (
	RowNumber INT IDENTITY (1, 1) NOT NULL,
	MaYeuCau int	
)

DECLARE @sql nvarchar(2000)
DECLARE @Top int

SET @Top = @Page*@PageSize
IF @PageSize > 0
   SET ROWCOUNT @Top
-- insert primary keys into temp table
SET @sql =	N'INSERT INTO #TempYeuCau ([MaYeuCau]) SELECT '
SET @sql = @sql + ' [MaYeuCau] FROM [sapro].[YeuCau]  ORDER BY [' + @OrderBy + N'] ' + @OrderDirection
EXEC (@sql)
SET ROWCOUNT 0

SELECT @TotalRecords = COUNT(*) FROM [YeuCau]

SELECT
	[Mobile],
	[sapro].[YeuCau].[MaYeuCau],
	[NoiDungYeuCau]
FROM
	#TempYeuCau AS tblTemp JOIN [sapro].[YeuCau] ON
	tblTemp.MaYeuCau = [sapro].[YeuCau].MaYeuCau 	
WHERE (@PageSize = 0) OR (@PageSize > 0 AND (@Page - 1)*@PageSize < RowNumber AND RowNumber <= @Page*@PageSize)
ORDER BY RowNumber

DROP TABLE #TempYeuCau

GO

/******************************************************************************
**		File: 
**		Name: [sapro].spYeuCauInsert
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:43 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spYeuCauInsert
	@Mobile nvarchar(20),
	@MaYeuCau int,
	@NoiDungYeuCau nvarchar(255)
AS

INSERT INTO [sapro].[YeuCau] 
(
	[Mobile],
	[MaYeuCau],
	[NoiDungYeuCau]
) 
VALUES 
(
	@Mobile,
	@MaYeuCau,
	@NoiDungYeuCau
)


GO
	
/******************************************************************************
**		File: 
**		Name: [sapro].spYeuCauUpdate
**		Desc: 
**
**		Return values:
** 
**		Called by:   
**              
**		Parameters:
**		Input							Output
**     ----------							-----------
**
**		Auth: CodeSmith
**		Date: 3/18/2010 5:05:43 PM
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE PROCEDURE [sapro].spYeuCauUpdate
	@Mobile nvarchar(20), 
	@MaYeuCau int, 
	@NoiDungYeuCau nvarchar(255) 
AS

UPDATE [sapro].[YeuCau] SET
	[Mobile] = @Mobile,
	[NoiDungYeuCau] = @NoiDungYeuCau
WHERE
	[MaYeuCau] = @MaYeuCau

GO


	